﻿// IPC Library
// Interprocess Communication Library
// Copyright(C)2008 Bill Tudorusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.ConstrainedExecution;
using Microsoft.Win32.SafeHandles;
using System;

namespace IPCLibrary
{
	[SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)]
	[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
	internal sealed class SafeViewOfFileHandle : SafeHandleZeroOrMinusOneIsInvalid
	{
		private SafeViewOfFileHandle()
            : base(true) {}
		/// <summary>
		/// Release the SafeHandle.
		/// </summary>
		/// <returns>Result from CloseHandle.</returns>
        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
        override protected bool ReleaseHandle()
        {
			return NativeMethods.UnmapViewOfFile(handle);
        }
		internal Int32 ToInt32()
		{
			return handle.ToInt32();
		}
	}
}
